<?php

declare(strict_types=1);
namespace App\Model\CommodityModel;

use App\Model\BaseModel\BaseCommodityModel;
use Hyperf\DbConnection\Db;
use App\Service\Code\Normal;

class Brandinfo extends BaseCommodityModel
{
    public $table = 'brandinfo_s2b';
    public function getBrandLists() {
        return self::query()
        ->where([
            ['IsDeleted','=',0]
        ])
        ->select([
            Db::raw('CONCAT(ID,"") as brand_id'),
            Db::raw('BrandName as brand_name'),
            Db::raw('CONCAT(0,"") as country_id'),
            Db::raw('IFNULL(Image,"") as brand_image'),
        ])
        ->get()
        ->toArray();
    }
    
    public function getBrandListsByIds( $ids = [] ) {
        return $this
        ->select([
            Db::raw('CONCAT(ID,"") as brand_id'),
            Db::raw('BrandName as brand_name'),
            Db::raw('CONCAT(0,"") as country_id'),
            Db::raw('CONCAT(Image,"") as Image'),
        ])
        ->whereIn('ID',$ids)
        ->get()
        ->toArray();
    }
    
    /**
     * 获取前N条数据
     * @param $param
     * @return mixed
     */
    public function getBrandTopLists( $limit = 0 )
    {
        $list = self::query()
        ->where([
            ['IsDeleted','=',0]
        ])
        ->select([
            Db::raw('CONCAT(ID,"") as ID'),
            Db::raw('BrandName'),
        ])
        ->limit($limit)
        ->get()
        ->toArray();
        
        return Normal::returnCode(Normal::SUC,"获取成功",[
            'topBrandList' => $list
        ]);
    }
}